2020-2021 Sunseeker Telemetry and Lighting System
adc12_a_ex7_sequence.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
75 //******************************************************************************
76 
77 #include "driverlib.h"
78 
79 //Needs to be global in this example
80 //Otherwise, the compiler removes it
81 //because it is not used for anything.
82 volatile uint16_t results[4];
83 
84 void main (void)
85 {
86  //Stop Watchdog Timer
87  WDT_A_hold(WDT_A_BASE);
88 
89  //Enable A/D channel inputs
90  GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
91  GPIO_PIN0 + GPIO_PIN1 + GPIO_PIN2 +
92  GPIO_PIN3 + GPIO_PIN4 + GPIO_PIN5 +
93  GPIO_PIN6 + GPIO_PIN7
94  );
95 
96  //Initialize the ADC12_A Module
97  /*
98  * Base address of ADC12_A Module
99  * Use internal ADC12_A bit as sample/hold signal to start conversion
100  * USE MODOSC 5MHZ Digital Oscillator as clock source
101  * Use default clock divider of 1
102  */
103  ADC12_A_init(ADC12_A_BASE,
104  ADC12_A_SAMPLEHOLDSOURCE_SC,
105  ADC12_A_CLOCKSOURCE_ADC12OSC,
106  ADC12_A_CLOCKDIVIDER_1);
107 
108  ADC12_A_enable(ADC12_A_BASE);
109 
110  /*
111  * Base address of ADC12_A Module
112  * For memory buffers 0-7 sample/hold for 16 clock cycles
113  * For memory buffers 8-15 sample/hold for 4 clock cycles (default)
114  * Enable Multiple Sampling
115  */
116  ADC12_A_setupSamplingTimer(ADC12_A_BASE,
117  ADC12_A_CYCLEHOLD_16_CYCLES,
118  ADC12_A_CYCLEHOLD_4_CYCLES,
119  ADC12_A_MULTIPLESAMPLESENABLE);
120 
121  //Configure Memory Buffers
122  /*
123  * Base address of the ADC12_A Module
124  * Configure memory buffer 0
125  * Map input A0 to memory buffer 0
126  * Vref+ = AVcc
127  * Vref- = AVss
128  * Memory buffer 0 is not the end of a sequence
129  */
130  ADC12_A_configureMemoryParam param0 = {0};
131  param0.memoryBufferControlIndex = ADC12_A_MEMORY_0;
132  param0.inputSourceSelect = ADC12_A_INPUT_A0;
133  param0.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
134  param0.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
135  param0.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
136  ADC12_A_configureMemory(ADC12_A_BASE ,&param0);
137 
138  /*
139  * Base address of the ADC12_A Module
140  * Configure memory buffer 1
141  * Map input A1 to memory buffer 1
142  * Vref+ = AVcc
143  * Vref- = AVss
144  * Memory buffer 1 is not the end of a sequence
145  */
146  ADC12_A_configureMemoryParam param1 = {0};
147  param1.memoryBufferControlIndex = ADC12_A_MEMORY_1;
148  param1.inputSourceSelect = ADC12_A_INPUT_A1;
149  param1.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
150  param1.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
151  param1.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
152  ADC12_A_configureMemory(ADC12_A_BASE ,&param1);
153 
154  /*
155  * Base address of the ADC12_A Module
156  * Configure memory buffer 2
157  * Map input A2 to memory buffer 2
158  * Vref+ = AVcc
159  * Vref- = AVss
160  * Memory buffer 2 is not the end of a sequence
161  */
162  ADC12_A_configureMemoryParam param2 = {0};
163  param2.memoryBufferControlIndex = ADC12_A_MEMORY_2;
164  param2.inputSourceSelect = ADC12_A_INPUT_A2;
165  param2.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
166  param2.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
167  param2.endOfSequence = ADC12_A_NOTENDOFSEQUENCE;
168  ADC12_A_configureMemory(ADC12_A_BASE ,&param2);
169 
170  /*
171  * Base address of the ADC12_A Module
172  * Configure memory buffer 3
173  * Map input A3 to memory buffer 3
174  * Vr+ = AVcc
175  * Vr- = AVss
176  * Memory buffer 3 IS the end of a sequence
177  */
178  ADC12_A_configureMemoryParam param3 = {0};
179  param3.memoryBufferControlIndex = ADC12_A_MEMORY_3;
180  param3.inputSourceSelect = ADC12_A_INPUT_A3;
181  param3.positiveRefVoltageSourceSelect = ADC12_A_VREFPOS_AVCC;
182  param3.negativeRefVoltageSourceSelect = ADC12_A_VREFNEG_AVSS;
183  param3.endOfSequence = ADC12_A_ENDOFSEQUENCE;
184  ADC12_A_configureMemory(ADC12_A_BASE ,&param3);
185 
186  //Enable memory buffer 3 interrupt
187  ADC12_A_clearInterrupt(ADC12_A_BASE,
188  ADC12IE3);
189  ADC12_A_enableInterrupt(ADC12_A_BASE,
190  ADC12IE3);
191 
192  while (1)
193  {
194  //Enable/Start first sampling and conversion cycle
195  /*
196  * Base address of ADC12_A Module
197  * Start the conversion into memory buffer 0
198  * Use the repeated sequence of channels
199  */
200  ADC12_A_startConversion(ADC12_A_BASE,
201  ADC12_A_MEMORY_0,
202  ADC12_A_SEQOFCHANNELS);
203 
204  //Enter LPM4, Enable interrupts
205  __bis_SR_register(LPM4_bits + GIE);
206  //For debugger
207  __no_operation();
208  }
209 }
210 
211 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
212 #pragma vector=ADC12_VECTOR
213 __interrupt
214 #elif defined(__GNUC__)
215 __attribute__((interrupt(ADC12_VECTOR)))
216 #endif
217 void ADC12ISR (void)
218 {
219  switch (__even_in_range(ADC12IV,34)){
220  case 0: break; //Vector 0: No interrupt
221  case 2: break; //Vector 2: ADC overflow
222  case 4: break; //Vector 4: ADC timing overflow
223  case 6: break; //Vector 6: ADC12IFG0
224  case 8: break; //Vector 8: ADC12IFG1
225  case 10: break; //Vector 10: ADC12IFG2
226  case 12: //Vector 12: ADC12IFG3
227  //Move results, IFG is cleared
228  results[0] =
229  ADC12_A_getResults(ADC12_A_BASE,
230  ADC12_A_MEMORY_0);
231  //Move results, IFG is cleared
232  results[1] =
233  ADC12_A_getResults(ADC12_A_BASE,
234  ADC12_A_MEMORY_1);
235  //Move results, IFG is cleared
236  results[2] =
237  ADC12_A_getResults(ADC12_A_BASE,
238  ADC12_A_MEMORY_2);
239  //Move results, IFG is cleared
240  results[3] =
241  ADC12_A_getResults(ADC12_A_BASE,
242  ADC12_A_MEMORY_3);
243 
244  //Exit active CPU, SET BREAKPOINT HERE
245  __bic_SR_register_on_exit(LPM4_bits);
246  case 14: break; //Vector 14: ADC12IFG4
247  case 16: break; //Vector 16: ADC12IFG5
248  case 18: break; //Vector 18: ADC12IFG6
249  case 20: break; //Vector 20: ADC12IFG7
250  case 22: break; //Vector 22: ADC12IFG8
251  case 24: break; //Vector 24: ADC12IFG9
252  case 26: break; //Vector 26: ADC12IFG10
253  case 28: break; //Vector 28: ADC12IFG11
254  case 30: break; //Vector 30: ADC12IFG12
255  case 32: break; //Vector 32: ADC12IFG13
256  case 34: break; //Vector 34: ADC12IFG14
257  default: break;
258  }
259 }
void main(void)
void ADC12ISR(void)
volatile uint16_t results[4]
__no_operation()
__bic_SR_register_on_exit(LPM3_bits|GIE)